Page({
  data: {
    startTime: '选择日期',
    endTime: '选择日期',
    startShow: false,
    endShow: false,
    timeIndex: 1,
    enterNum: '111',
    outNum: '90',
    stayNum: '21',
    detailSelect: ['进场', '出场', '待修'],
    detailList: [],
    formList: []
  },
  onLoad (option) {
    console.log(option)
    const that = this
    const eventChannel = this.getOpenerEventChannel()
    eventChannel.on('detailList', function (data) {
      data.map((item) => {
        if (item.chuchangshijian === null) {
          item.chuchangshijian = ''
        }
      })
      that.setData({ detailList: data, formList: data })
    })
  },

  handleChange (e) {
    if (e.detail.index == 0) {
      this.setData({ detailList: this.data.formList })
    } else if (e.detail.index == 1) {
      const filteredData = this.data.formList.filter((item) => {
        return item.chuchangshijian != ''
      });
      this.setData({ detailList: filteredData })

    } else if (e.detail.index == 2) {
      const filteredData = this.data.formList.filter((item) => {
        return item.chuchangshijian == ''
      });
      this.setData({ detailList: filteredData })
    }
  },

  onDisplay (e) {
    this.data.timeIndex = e.currentTarget.dataset.index
    if (this.data.timeIndex == 1) {
      this.setData({ startShow: true });
    } else if (this.data.timeIndex == 2) {
      this.setData({ endShow: true });
    }


  },
  onClose () {

    if (this.data.timeIndex == 1) {
      this.setData({ startShow: false });
    } else if (this.data.timeIndex == 2) {
      this.setData({ endShow: false });
    }
  },
  formatDate (date) {
    date = new Date(date);
    return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`;
  },
  onConfirm (event) {
    if (this.data.timeIndex == 1) {
      this.setData({
        startShow: false,
        startTime: this.formatDate(event.detail),
      });
    } else if (this.data.timeIndex == 2) {
      this.setData({
        endShow: false,
        endTime: this.formatDate(event.detail),
      });
    }

  },

})
